package com.atguigu;

import java.util.*;

/**
 * @ClassName HashCodeTest
 * @Author yy
 * @create 2022/9/7 18:45
 */

//哈希碰撞
public class HashCodeTest {
    public static void main(String[] args) {
        List list = new ArrayList();
//        Set set = new HashSet();
        int mode = 0;
//大于100000次才会出现
        for (int i = 0; i < 120000; i++) {
            mode = new Object().hashCode();
            if (list.contains(mode)){
                System.out.println("在第"+ i +"次,出现哈希碰撞,哈希值为:"+mode);
                continue;
            }
            list.add(mode);
//            set.add(mode);
        }
        System.out.println("数组长度为:"+list.size());
//        System.out.println("数组长度为:"+set.size());
    }
}
